home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1995…tember: Reference Library / Dev.CD Sep 95 RL / Dev.CD Sep 95 RL.toast / mac / Technical Documentation / develop / develop Issue 23 code / Documentary Synchronicity ƒ / Source ƒ / Support ƒ / ProcessInfo.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-06-05  |  2.6 KB  |  102 lines  |  [TEXT/KAHL]

  1. /* 4567890123456789012345678901234567890123456789012345678901234567 */
  2. #include <Processes.h>
  3.  
  4. #include "ProcessInfo.h"
  5.  
  6. pascal OSErr InBackground(Boolean *inBackground) {
  7.     ProcessSerialNumber theCurrentProcess;
  8.     ProcessSerialNumber theFrontProcess;
  9.     Boolean sameProcess;
  10.     OSErr theError;
  11.     
  12.     theError = GetCurrentProcess(&theCurrentProcess);
  13.     if (theError == noErr) {
  14.         theError = GetFrontProcess(&theFrontProcess);
  15.     }
  16.     if (theError == noErr) {
  17.         theError = SameProcess(&theCurrentProcess, &theFrontProcess, 
  18.             &sameProcess);
  19.         if ((theError == noErr) && sameProcess) {
  20.             *inBackground = false;
  21.         } else {
  22.             *inBackground = true;
  23.         }
  24.     }
  25.     return theError;
  26. }
  27.  
  28. pascal OSType GetSignature(void) {
  29.     OSErr theError;
  30.     OSType theSignature;
  31.     ProcessInfoRec theInformation;
  32.     ProcessSerialNumber theCurrentProcess;
  33.     
  34.     theInformation.processInfoLength = sizeof(ProcessInfoRec);
  35.     theInformation.processName = nil; /* Don't care about name */
  36.     theInformation.processAppSpec = nil; /* Don't care about spec */
  37.     
  38.     theError = GetCurrentProcess(&theCurrentProcess);
  39.     if (theError == noErr) {
  40.         theError = 
  41.             GetProcessInformation(&theCurrentProcess, &theInformation);
  42.     }
  43.     if (theError == noErr) {
  44.         theSignature = theInformation.processSignature;
  45.     } else {
  46.         theSignature = '????';
  47.     }
  48.     return theSignature;
  49. }
  50.  
  51. pascal OSErr GetProcessName(Str31 aName) {
  52.     OSErr theError;
  53.     ProcessInfoRec theInformation;
  54.     ProcessSerialNumber theCurrentProcess;
  55.     
  56.     theInformation.processInfoLength = sizeof(ProcessInfoRec);
  57.     theInformation.processName = aName;
  58.     theInformation.processAppSpec = nil; /* Don't care about spec */
  59.     
  60.     theError = GetCurrentProcess(&theCurrentProcess);
  61.     if (theError == noErr) {
  62.         theError = 
  63.             GetProcessInformation(&theCurrentProcess, &theInformation);
  64.     }
  65.     return theError;
  66. }
  67.  
  68. #define kSystemType    'FNDR'
  69. #define kFinderSig    'MACS'
  70.  
  71. pascal OSErr FindFinder(ProcessSerialNumberPtr aPSN) {
  72.     ProcessInfoRec    theInformation;
  73.     OSErr theError = noErr;
  74.  
  75.     aPSN->lowLongOfPSN = 0;
  76.     aPSN->highLongOfPSN = kNoProcess;
  77.     theInformation.processInfoLength = sizeof(ProcessInfoRec);
  78.     theInformation.processName = nil; /* Don't care about name */
  79.     theInformation.processAppSpec = nil; /* Don't care about spec */
  80.     do {
  81.         theError = GetNextProcess(aPSN);
  82.         if (theError == noErr) {
  83.             GetProcessInformation(aPSN, &theInformation);
  84.         }
  85.     } while(((theInformation.processSignature != kFinderSig) ||
  86.         (theInformation.processType != kSystemType)) &&
  87.         (theError == noErr));
  88.     return(theError);
  89. }
  90.  
  91. pascal OSErr BringFinderToFront(void) {
  92.     OSErr theError;
  93.     ProcessSerialNumber theFinder;
  94.     
  95.     theError = FindFinder(&theFinder);
  96.     if (theError == noErr) {
  97.         theError = SetFrontProcess(&theFinder);
  98.     }
  99.     return theError;
  100. }
  101.  
  102.